﻿using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System;
using System.Collections.Generic;
using LuaInterface;
using LuaFramework;
using System.Collections;
using BindType = ToLuaMenu.BindType;
using System.IO;
using DG.Tweening;
using UnityEngine.SceneManagement;
using UnityEngine.Tilemaps;
using UnityEngine.EventSystems;

public static class CustomSettings
{
    public static string saveDir = Application.dataPath + "/ToLua/Source/Generate/";    
    public static string toluaBaseType = Application.dataPath + "/ToLua/BaseType/";
    public static string baseLuaDir = Application.dataPath + string.Format("/{0}/Lua", AppConst.AppName);
    public static string injectionFilesPath = Application.dataPath + "/ToLua/Injection/";

    //导出时强制做为静态类的类型(注意customTypeList 还要添加这个类型才能导出)
    //unity 有些类作为sealed class, 其实完全等价于静态类
    public static List<Type> staticClassTypes = new List<Type>
    {        
        typeof(UnityEngine.Application),
        typeof(UnityEngine.Time),
        typeof(UnityEngine.Screen),
        typeof(UnityEngine.SleepTimeout),
        typeof(UnityEngine.Input),
        typeof(UnityEngine.Resources),
        typeof(UnityEngine.Physics),
        typeof(UnityEngine.RenderSettings),
        typeof(UnityEngine.QualitySettings),
        typeof(UnityEngine.GL),
        typeof(UnityEngine.Graphics),
    };

    //附加导出委托类型(在导出委托时, customTypeList 中牵扯的委托类型都会导出， 无需写在这里)
    public static DelegateType[] customDelegateList = 
    {
        _DT(typeof(Action)),
        _DT(typeof(UnityEngine.Events.UnityAction)),
        _DT(typeof(Predicate<int>)),
        _DT(typeof(Action<int>)),
        _DT(typeof(Comparison<int>)),
        _DT(typeof(DG.Tweening.TweenCallback)),
        _DT(typeof(Action<GameObject>)),
        _DT(typeof(Action<GameObject, GameObject>)),
        _DT(typeof(Action<string>)),
        _DT(typeof(InputField.OnValidateInput)),

    };

    //在这里添加你要导出注册到lua的类型列表
    public static BindType[] customTypeList =
    {                
        //System
        _GT(typeof(File)),
        _GT(typeof(Directory)),
        _GT(typeof(Path)),
        _GT(typeof(Dictionary<string, string>)),
        _GT(typeof(Dictionary<string, object>)),

        _GT(typeof(LuaInjectionStation)),
        _GT(typeof(InjectType)),
        _GT(typeof(Debugger)).SetNameSpace(null),
        _GT(typeof(UnityEngine.SystemLanguage)),
        
        // DOTWEENING
        _GT(typeof(DG.Tweening.DOTween)),
        _GT(typeof(DG.Tweening.DOTweenAnimation)),
        _GT(typeof(DG.Tweening.Tween)).SetBaseType(typeof(System.Object)).AddExtendType(typeof(DG.Tweening.TweenExtensions)),
        _GT(typeof(DG.Tweening.Sequence)).AddExtendType(typeof(DG.Tweening.TweenSettingsExtensions)),
        _GT(typeof(DG.Tweening.Tweener)).AddExtendType(typeof(DG.Tweening.TweenSettingsExtensions)),
        _GT(typeof(DG.Tweening.LoopType)),
        _GT(typeof(DG.Tweening.PathMode)),
        _GT(typeof(DG.Tweening.PathType)),
        _GT(typeof(DG.Tweening.RotateMode)),
        _GT(typeof(Ease)),
        _GT(typeof(TweenParams)),
        _GT(typeof(Component)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Transform)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Material)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Rigidbody)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(Camera)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(AudioSource)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(LineRenderer)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(TrailRenderer)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions)),
        _GT(typeof(RectTransform)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)),
        _GT(typeof(Slider)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)),

        _GT(typeof(Behaviour)),
        _GT(typeof(MonoBehaviour)),
        _GT(typeof(MonoBehaviourCallback)),
        _GT(typeof(AnimatorStateEvent)),
        _GT(typeof(ColliderEnterTrigger)),
        _GT(typeof(ColliderLeaveTrigger)),
        _GT(typeof(GameObject)),
        _GT(typeof(TrackedReference)),
        _GT(typeof(Application)),
        _GT(typeof(QualitySettings)),
        _GT(typeof(ThreadPriority)),
        _GT(typeof(Resources)),
        _GT(typeof(Physics)),
        _GT(typeof(Collider)),
        _GT(typeof(Time)),
        _GT(typeof(Texture)),
        _GT(typeof(Texture2D)).AddExtendType(typeof(ImageConversion)),
        _GT(typeof(Shader)),
        _GT(typeof(Renderer)),
        _GT(typeof(Screen)),
        _GT(typeof(CameraClearFlags)),
        _GT(typeof(AudioClip)),
        _GT(typeof(AssetBundle)),
        _GT(typeof(ParticleSystem)),
        _GT(typeof(ParticleSystem.MainModule)),
        _GT(typeof(ParticleSystemRenderer)),
        _GT(typeof(AsyncOperation)).SetBaseType(typeof(System.Object)),
        _GT(typeof(LightType)),
        _GT(typeof(SleepTimeout)),
        _GT(typeof(Animator)),
        _GT(typeof(AnimatorStateInfo)),
        _GT(typeof(RuntimeAnimatorController)),
        _GT(typeof(AnimatorControllerParameter)),        
        _GT(typeof(Input)),
        _GT(typeof(KeyCode)),
        _GT(typeof(SkinnedMeshRenderer)),
        _GT(typeof(Space)),
        _GT(typeof(MeshRenderer)),
        _GT(typeof(SceneManager)),
        _GT(typeof(Scene)),
        _GT(typeof(BoxCollider)),
        _GT(typeof(MeshCollider)),
        _GT(typeof(SphereCollider)),
        _GT(typeof(CharacterController)),
        _GT(typeof(CapsuleCollider)),
        _GT(typeof(Animation)),
        _GT(typeof(AnimationClip)).SetBaseType(typeof(UnityEngine.Object)),
        _GT(typeof(AnimationState)),
        _GT(typeof(AnimationBlendMode)),
        _GT(typeof(QueueMode)),
        _GT(typeof(PlayMode)),
        _GT(typeof(WrapMode)),
        _GT(typeof(ImageConversion)),
        _GT(typeof(SystemInfo)),
        _GT(typeof(PlatformUtilsSharp)),
        _GT(typeof(RenderSettings)),
        _GT(typeof(BlendWeights)),
        _GT(typeof(RenderTexture)),
        _GT(typeof(RenderTextureFormat)),
        _GT(typeof(Debug)),
        _GT(typeof(Matrix4x4)),
        _GT(typeof(LogType)),
          
        //for LuaFramework
        _GT(typeof(Util)),
        _GT(typeof(AppConst)),
        _GT(typeof(LuaBehaviour)),
        _GT(typeof(AppFacade)),
        _GT(typeof(GameManager)),
        _GT(typeof(SoundManager)),
        _GT(typeof(TimerManager)),
        _GT(typeof(ResourceManager)),
        _GT(typeof(LoadManager)),
        _GT(typeof(BundleManager)),
        _GT(typeof(RecorderManager)),
        _GT(typeof(DatabaseManager)),
        _GT(typeof(DatabaseQueryJob)),
        _GT(typeof(DatabaseNonQueryJob)),
        _GT(typeof(NetworkManager)),
        _GT(typeof(Network.TcpChannel)),
        _GT(typeof(Network.KcpChannel)),
        _GT(typeof(GZipDecompresser)),
        _GT(typeof(GZipCompresser)),
        _GT(typeof(EventManager)),
        _GT(typeof(ThreadManager)),
        _GT(typeof(ThreadJob)),
        _GT(typeof(DownloadHandlerFileRange)),


        _GT(typeof(TouchScreenKeyboardType)),
        _GT(typeof(PlayerPrefs)),
        _GT(typeof(TextAsset)),

        _GT(typeof(Resolution)),
        _GT(typeof(Font)),
        _GT(typeof(Uri)),

        _GT(typeof(RuntimePlatform)),
        _GT(typeof(LoadSource)),
        _GT(typeof(LuaUtil)),
        _GT(typeof(LuaUnzipHelper)),
        _GT(typeof(Hashtable)),
        _GT(typeof(LoadTaskR)),
        _GT(typeof(sbyte)),
        _GT(typeof(byte)),
        _GT(typeof(short)),
        _GT(typeof(ushort)),
        _GT(typeof(int)),
        _GT(typeof(uint)),
        _GT(typeof(long)),
        _GT(typeof(ulong)),
        _GT(typeof(bool)),
        _GT(typeof(UnityEngine.Random)),
        _GT(typeof(Rect)),
        _GT(typeof(DateTime)),
        _GT(typeof(TimeSpan)),
       
        _GT(typeof(UnityEngine.Networking.UnityWebRequest)),
        _GT(typeof(UnityEngine.Networking.DownloadHandler)),
        _GT(typeof(UnityEngine.Networking.DownloadHandlerBuffer)),
        _GT(typeof(WWWForm)),
        _GT(typeof(UnityEngine.Networking.MultipartFormDataSection)),
        _GT(typeof(UnityEngine.Networking.MultipartFormFileSection)),
        _GT(typeof(List<UnityEngine.Networking.IMultipartFormSection>)),
        
         
        _GT(typeof(CrashLogger)),
        _GT(typeof(VersionInfo)),
        //UGUI
        _GT(typeof(Text)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)),
        _GT(typeof(Outline)),    
        _GT(typeof(Canvas)),
        _GT(typeof(CanvasScaler)),
        _GT(typeof(CanvasGroup)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)),
        _GT(typeof(LayoutRebuilder)),
        _GT(typeof(Button)),
        _GT(typeof(PressReleaseButton)),
        _GT(typeof(Image)).AddExtendType(typeof(DG.Tweening.ShortcutExtensions46)),
        _GT(typeof(RawImage)),
        _GT(typeof(HorizontalWrapMode)),
        _GT(typeof(HorizontalLayoutGroup)),
        _GT(typeof(GridLayoutGroup)),
        _GT(typeof(EmojiInlineText)),
        _GT(typeof(ScrollRect)),
        _GT(typeof(ScrollRect.ScrollRectEvent)),
        _GT(typeof(Scrollbar)),
        _GT(typeof(RectTransformUtility)),
        _GT(typeof(Button.ButtonClickedEvent)),
        _GT(typeof(Slider.SliderEvent)),
        _GT(typeof(Sprite)),
        _GT(typeof(Toggle)),
        _GT(typeof(ToggleGroup)),
        _GT(typeof(InputField)),
        _GT(typeof(InputField.OnChangeEvent)),
        _GT(typeof(InputField.SubmitEvent)),
       
        _GT(typeof(Toggle.ToggleEvent)),
        _GT(typeof(EventListener)),
        _GT(typeof(ButtonAnimation)),
        _GT(typeof(UnityEngine.EventSystems.EventSystem)),
        _GT(typeof(UnityEngine.EventSystems.ExecuteEvents)),
        _GT(typeof(UnityEngine.EventSystems.RaycastResult)),
        _GT(typeof(UnityEngine.EventSystems.PointerEventData)),
        _GT(typeof(BezierUtils)),
        _GT(typeof(LightProbeCtrl)),
        _GT(typeof(SetColor)),
        _GT(typeof(TextMesh)),
        _GT(typeof(SpriteRenderer)),
        _GT(typeof(Shadow)),
        _GT(typeof(LayoutElement)),
        _GT(typeof(TextGenerator)),
        _GT(typeof(TextGenerationSettings)),
        
        //spine
        _GT(typeof(Spine.Unity.SkeletonAnimation)),
        _GT(typeof(Spine.Unity.SkeletonRenderer)),
        _GT(typeof(Spine.AnimationState)),
        _GT(typeof(Spine.Animation)),
        _GT(typeof(Spine.TrackEntry)),
        _GT(typeof(Spine.Skeleton)),
        _GT(typeof(Spine.Skin)),
        _GT(typeof(Spine.Attachment)),
        
        _GT(typeof(Spine.Unity.SkeletonGraphic)),
       
        //sqlite
        _GT(typeof(SqliteDatabase)),
        _GT(typeof(DataTable)),
        _GT(typeof(DataRow)),

        //hex dump
        _GT(typeof(Binutils)),

        _GT(typeof(Tilemap)),
        _GT(typeof(Grid)),
        _GT(typeof(Vector2Int)),
        _GT(typeof(Vector3Int)),
        _GT(typeof(TileBase)),
        _GT(typeof(TileData)),
        _GT(typeof(TileMapEditor.TileAssetHolder)),

         _GT(typeof(UIBehaviour)),
         _GT(typeof(ShieldEmojiInputField)),
         
         //emoji
         _GT(typeof(EmojiTranslate)),
         _GT(typeof(EmojiInputField)),
         
         _GT(typeof(SpritePatternModifier)),
         _GT(typeof(BlockTileManager)),

         _GT(typeof(MaterialPropertyBlock)),
         //Clipboard
         _GT(typeof(GUIUtility)),
         _GT(typeof(MD5Helper)),
    };

    public static List<Type> dynamicList = new List<Type>()
    {
        typeof(MeshRenderer),

        typeof(BoxCollider),
        typeof(MeshCollider),
        typeof(SphereCollider),
        typeof(CharacterController),
        typeof(CapsuleCollider),

        typeof(Animation),
        typeof(AnimationClip),
        typeof(AnimationState),

        typeof(BlendWeights),
        typeof(RenderTexture),
        typeof(Rigidbody),

        
    };

    //重载函数，相同参数个数，相同位置out参数匹配出问题时, 需要强制匹配解决
    //使用方法参见例子14
    public static List<Type> outList = new List<Type>()
    {
        
    };
        
    //ngui优化，下面的类没有派生类，可以作为sealed class
    public static List<Type> sealedList = new List<Type>()
    {
        
    };

    public static BindType _GT(Type t)
    {
        return new BindType(t);
    }

    public static DelegateType _DT(Type t)
    {
        return new DelegateType(t);
    }    


    [MenuItem("Lua/Attach Profiler", false, 151)]
    static void AttachProfiler()
    {
        if (!Application.isPlaying)
        {
            EditorUtility.DisplayDialog("警告", "请在运行时执行此功能", "确定");
            return;
        }

        LuaClient.Instance.AttachProfiler();
    }

    [MenuItem("Lua/Detach Profiler", false, 152)]
    static void DetachProfiler()
    {
        if (!Application.isPlaying)
        {            
            return;
        }

        LuaClient.Instance.DetachProfiler();
    }
}
